home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-05 | 4.3 KB | 184 lines | [TEXT/MPS ] |
- {$R-}
- {$S PopUpMenu }
-
- {
-
- PopUpMenu(MenuItems, CheckedItem, Top, Left)
-
- This HyperCard external function returns the selection from a popup
- menu created from a HyperCard item list (the first parameter). The
- menu is placed on the screen so that the checked item is at the
- position (Top, Left) in global coordinates.
-
- It uses the DoPopUpMenu function from the MenuTools unit.
-
- It is better than most PopUpMenu implementations (he said modestly)
- because it is not limited to 256 characters’ worth of menu items.
-
- }
-
- UNIT DummyUnit;
-
- INTERFACE
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, MenuTools;
-
- PROCEDURE EntryPoint(paramPtr: XCmdPtr);
-
- IMPLEMENTATION
-
- PROCEDURE PopUpMenu(paramPtr: XCmdPtr);
- FORWARD;
-
- PROCEDURE EntryPoint(paramPtr: XCmdPtr);
- BEGIN
- PopUpMenu(paramPtr)
- END { entrypoint } ;
-
-
- PROCEDURE PopUpMenu(paramPtr: XCmdPtr);
-
- CONST
- MenuID = 128;
-
- VAR
- MenuItems: Ptr;
- CheckedItem: LONGINT;
- SelectedItem: LONGINT;
- Top: LONGINT;
- Left: LONGINT;
- CardWindowTop: LONGINT;
- CardWindowLeft: LONGINT;
-
-
- FUNCTION ParamToNum(Param: Handle): LongInt;
-
- VAR
- Str: Str255;
-
- BEGIN
- ZeroToPas(ParamPtr, Param^, Str);
- ParamToNum := StrToNum(ParamPtr, Str);
- END { ParamToNum } ;
-
- FUNCTION NumToParam(Num: LongInt): Handle;
-
- VAR
- Str: Str255;
-
- BEGIN
- NumToStr(ParamPtr, Num, Str);
- NumToParam := PasToZero(ParamPtr, Str)
- END { NumToParam } ;
-
- PROCEDURE GetCardWindowParams(VAR CardWindowTop: LONGINT;
- VAR CardWindowLeft: LONGINT);
- VAR
- WindowTopString: Handle;
- WindowLeftString: Handle;
- AString: Str255;
- BEGIN
-
- WindowTopString := EvalExpr(ParamPtr, 'the top of card window');
- WindowLeftString := EvalExpr(ParamPtr, 'the left of card window');
- ZeroToPas(ParamPtr, WindowTopString^, AString);
- CardWindowTop := StrToNum(ParamPtr, AString);
-
- ZeroToPas(ParamPtr, WindowLeftString^, AString);
- CardWindowLeft := StrToNum(ParamPtr, AString);
-
- DisposHandle(WindowTopString);
- DisposHandle(WindowLeftString);
-
- END {GetCardWindowParams} ;
-
- PROCEDURE AppendAllMenuItemsPtr(Menu: MenuHandle; MenuItems: Ptr);
-
- VAR
- StartPos: LONGINT;
- EndHasBeenReached: Boolean;
- NewLength: INTEGER;
- PasMenuItems: Str255;
- BEGIN
-
- { The input is a Ptr string (C-style string) containing possibly
- more than 250 characters of menu items to be added to the list.
- We break the input up into 250 character chunks as many times as possible,
- calling AppendAllMenuItems on each chunk. }
-
- StartPos := 0;
- EndHasBeenReached := false;
-
- REPEAT
-
- ZeroToPas(ParamPtr, Pointer(Ord4(MenuItems) + StartPos), PasMenuItems);
- NewLength := length(PasMenuItems);
-
- IF (NewLength > 250) THEN
- BEGIN
- FOR NewLength := 250 DOWNTO 1 DO
- IF (PasMenuItems[NewLength] = ',') THEN Leave;
- NewLength := NewLength - 1;
- IF (NewLength) = 0 THEN Exit(AppendAllMenuItemsPtr);
- PasMenuItems[0] := chr(NewLength)
- END
- ELSE
- EndHasBeenReached := true;
- AppendAllMenuItems(Menu, PasMenuItems);
- StartPos := StartPos + NewLength + 1
-
- UNTIL (EndHasBeenReached = true);
-
- END { AppendAllMenuItemsPtr } ;
-
- FUNCTION DoPopUpMenuPtr(MenuID: INTEGER; MenuItems: Ptr; CheckedItem: LONGINT;
- Top: LONGINT; Left: LONGINT): LONGINT;
- VAR
- Menu: MenuHandle;
-
- BEGIN
-
- { Create the PopUp menu }
- Menu := NewMenu(MenuID, '');
- AppendAllMenuItemsPtr(Menu, MenuItems);
- CheckItem(Menu, CheckedItem, true);
- InsertMenu(Menu, - 1);
-
- { Get Menu Selection }
- DoPopUpMenuPtr := PopUpMenuSelect(Menu, Top, Left, CheckedItem);
-
- { Tidy up }
- DeleteMenu(MenuID);
- DisposeMenu(Menu);
-
- END; {DoPopUpMenuPtr}
-
- BEGIN {PopUpMenu}
-
- WITH paramPtr^ DO
- BEGIN
-
- { Parse parameters & Get Menu Position }
- MenuItems := Params[1]^;
- CheckedItem := ParamToNum(Params[2]);
- GetCardWindowParams(CardWindowTop, CardWindowLeft);
- Top := CardWindowTop + ParamToNum(Params[3]);
- Left := CardWindowLeft + ParamToNum(Params[4]);
-
- { Run the popup menu }
- IF (StringLength(ParamPtr, MenuItems) <> 0) THEN
- SelectedItem := DoPopUpMenuPtr(MenuID, MenuItems, CheckedItem, Top, Left)
- ELSE
- SelectedItem := 0;
-
- { Return the selection }
- returnValue := NumToParam(LoWord(SelectedItem))
-
- END
-
- END { PopUpMenu } ;
-
- END. { DummyUnit }
-
-
-